<template>
	<div class="page-wrap">
		<div class="page-content p-0">
			<div class="page-column p-0">
				<div class="page-form p-x-0">
					<el-form
						:model="ruleForm"
						:rules="rules"
						label-position="left"
						label-width="154px"
						ref="form"
						label-suffix="："
					>
						<el-row>
							<el-col :span="24">
								<el-form-item label="干沉降沉降速度" prop="DDNPSGRP001">
									<el-input
										size="medium"
										class="mediumForm"
										@input="addDDNPSGRPNum"
										v-model.number="ruleForm.DDNPSGRPNum"
									>
										<template slot="append">套</template>
									</el-input>
								</el-form-item>
								<el-tabs class="m-20" v-model="activeName" type="card">
									<el-tab-pane
										:label="item.index"
										:name="item.index"
										v-for="(item,index) in ruleForm.DDNPSGRPList"
										:key="index"
									>
										<el-form-item label="干沉降速度" prop="name"></el-form-item>
										<el-table ref="multipleTable" :data="item.DDNPSGRPtab" tooltip-effect="dark" border>
											<el-table-column
												prop="RDCORINV_COR1"
												label="干沉降组1"
												align="center"
												min-width="120"
												v-if="ruleForm.DDNPSGRP001 >= 1"
											>
												<template slot-scope="scope">
													<el-form-item
														label-width="0px"
														:rules="rules.RDCORINV_COR1"
														:prop="'DDNPSGRPtab.'+scope.$index+'.RDCORINV_COR1'"
													>
														<el-input
															minlength="1"
															maxlength="20"
															oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,3})?).*$/g, '$1')"
															class="bigForm"
															v-model="scope.row.RDCORINV_COR1"
														></el-input>
													</el-form-item>
												</template>
											</el-table-column>
											<el-table-column
												prop="RDCORINV_COR2"
												label="干沉降组2"
												align="center"
												min-width="120"
												v-if="ruleForm.DDNPSGRP001 >= 2"
											>
												<template slot-scope="scope">
													<el-form-item
														label-width="0px"
														:rules="rules.RDCORINV_COR2"
														:prop="'DDNPSGRPtab.'+scope.$index+'.RDCORINV_COR2'"
													>
														<el-input
															minlength="1"
															maxlength="20"
															oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,3})?).*$/g, '$1')"
															class="bigForm"
															v-model="scope.row.RDCORINV_COR2"
														></el-input>
													</el-form-item>
												</template>
											</el-table-column>
											<el-table-column
												prop="RDCORINV_COR3"
												label="干沉降组3"
												align="center"
												min-width="120"
												v-if="ruleForm.DDNPSGRP001 >= 3"
											>
												<template slot-scope="scope">
													<el-form-item
														label-width="0px"
														:rules="rules.RDCORINV_COR3"
														:prop="'DDNPSGRPtab.'+scope.$index+'.RDCORINV_COR3'"
													>
														<el-input
															minlength="1"
															maxlength="20"
															oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,3})?).*$/g, '$1')"
															class="bigForm"
															v-model="scope.row.RDCORINV_COR3"
														></el-input>
													</el-form-item>
												</template>
											</el-table-column>
											<el-table-column
												prop="RDCORINV_COR4"
												label="干沉降组4"
												align="center"
												min-width="120"
												v-if="ruleForm.DDNPSGRP001 >= 4"
											>
												<template slot-scope="scope">
													<el-form-item
														label-width="0px"
														:rules="rules.RDCORINV_COR4"
														:prop="'DDNPSGRPtab.'+scope.$index+'.RDCORINV_COR4'"
													>
														<el-input
															oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,3})?).*$/g, '$1')"
															class="bigForm"
															v-model="scope.row.RDCORINV_COR4"
														></el-input>
													</el-form-item>
												</template>
											</el-table-column>
											<el-table-column
												prop="RDCORINV_COR5"
												label="干沉降组5"
												align="center"
												min-width="120"
												v-if="ruleForm.DDNPSGRP001 >= 5
											"
											>
												<template slot-scope="scope">
													<el-form-item
														label-width="0px"
														:rules="rules.RDCORINV_COR5"
														:prop="'DDNPSGRPtab.'+scope.$index+'.RDCORINV_COR5'"
													>
														<el-input
															oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,3})?).*$/g, '$1')"
															class="bigForm"
															v-model="scope.row.RDCORINV_COR5"
														></el-input>
													</el-form-item>
												</template>
											</el-table-column>
											<el-table-column
												prop="RDCORINV_COR6"
												label="干沉降组6"
												align="center"
												min-width="120"
												v-if="ruleForm.DDNPSGRP001 >= 6
											"
											>
												<template slot-scope="scope">
													<el-form-item
														label-width="0px"
														:rules="rules.RDCORINV_COR6"
														:prop="'DDNPSGRPtab.'+scope.$index+'.RDCORINV_COR6'"
													>
														<el-input
															oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,3})?).*$/g, '$1')"
															class="bigForm"
															v-model="scope.row.RDCORINV_COR6"
														></el-input>
													</el-form-item>
												</template>
											</el-table-column>
											<el-table-column
												prop="RDCORINV_COR7"
												label="干沉降组7"
												align="center"
												min-width="120"
												v-if="ruleForm.DDNPSGRP001 >= 7
											"
											>
												<template slot-scope="scope">
													<el-form-item
														label-width="0px"
														:rules="rules.RDCORINV_COR7"
														:prop="'DDNPSGRPtab.'+scope.$index+'.RDCORINV_COR7'"
													>
														<el-input
															oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,3})?).*$/g, '$1')"
															class="bigForm"
															v-model="scope.row.RDCORINV_COR7"
														></el-input>
													</el-form-item>
												</template>
											</el-table-column>
											<el-table-column
												prop="RDCORINV_COR8"
												label="干沉降组8"
												align="center"
												min-width="120"
												v-if="ruleForm.DDNPSGRP001 >= 8
											"
											>
												<template slot-scope="scope">
													<el-form-item
														label-width="0px"
														:rules="rules.RDCORINV_COR8"
														:prop="'DDNPSGRPtab.'+scope.$index+'.RDCORINV_COR8'"
													>
														<el-input
															oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,3})?).*$/g, '$1')"
															class="bigForm"
															v-model="scope.row.RDCORINV_COR8"
														></el-input>
													</el-form-item>
												</template>
											</el-table-column>
											<el-table-column
												prop="RDCORINV_COR9"
												label="干沉降组9"
												align="center"
												min-width="120"
												v-if="ruleForm.DDNPSGRP001 >= 9
											"
											>
												<template slot-scope="scope">
													<el-form-item
														label-width="0px"
														:rules="rules.RDCORINV_COR9"
														:prop="'DDNPSGRPtab.'+scope.$index+'.RDCORINV_COR9'"
													>
														<el-input
															oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,3})?).*$/g, '$1')"
															class="bigForm"
															v-model="scope.row.RDCORINV_COR9"
														></el-input>
													</el-form-item>
												</template>
											</el-table-column>
											<el-table-column
												prop="RDCORINV_COR10"
												label="干沉降组10"
												align="center"
												min-width="120"
												v-if="ruleForm.DDNPSGRP001 >= 10
											"
											>
												<template slot-scope="scope">
													<el-form-item
														label-width="0px"
														:rules="rules.RDCORINV_COR10"
														:prop="'DDNPSGRPtab.'+scope.$index+'.RDCORINV_COR10'"
													>
														<el-input
															oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,3})?).*$/g, '$1')"
															class="bigForm"
															v-model="scope.row.RDCORINV_COR10"
														></el-input>
													</el-form-item>
												</template>
											</el-table-column>
										</el-table>
									</el-tab-pane>
								</el-tabs>
							</el-col>
						</el-row>
					</el-form>
				</div>
				<div class="bottom-btn">
					<el-button
						type="primary"
						:disabled="this.senstivity_Data.DDNPSGRPNum>0"
						:loading="loading"
						@click="submitFun"
					>下一步</el-button>
					<el-button
						type="primary"
						v-if="this.senstivity_Data.DDNPSGRPNum>0"
						:loading="loading"
						@click="tijiao"
					>提 交</el-button>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import selectPara from "@/components/selectPara"
import commCheckbox from "@/components/commCheckbox"
import ImageCropper from "@/components/ImageCropper"
import FixBottomButton from "@/components/FixBottomButton"
import ueditor from "@/components/ueditor"
import textLength from "@/components/common/comp/textLength"
import { commPara } from "@/mixins/mixins"
import { mapState } from "vuex"
import Axios from "axios"
import { dome, selecttext } from "@/utils/verify.js"

export default {
	name: "aboutUs",
	props: {},
	mixins: [commPara],
	components: {
		selectPara,
		ImageCropper,
		textLength,
		commCheckbox,
		FixBottomButton,
		ueditor,
	},

	data() {
		var CHEVACST001 = (rule, value, callback) => {
			// console.log(rule)
			// console.log(value)
			// console.log(callback)
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 0.0 || value > 1000.0) {
				callback(new Error("输入范围为[0.0，1000.0]"))
			} else {
				callback()
			}
		}

		return {
			activeTab: "3",
			DDNPSGRPoptions: [],
			activeName: "1",
			ruleForm: {
				DDNPSGRPNum: "0",
				DDNPSGRPList: [],

				DDNPSGRPtab: [
					{
						RDCORINV_COR1: "",
						RDCORINV_COR2: "",
						RDCORINV_COR3: "",
						RDCORINV_COR4: "",
						RDCORINV_COR5: "",
						RDCORINV_COR6: "",
						RDCORINV_COR8: "",
						RDCORINV_COR9: "",
						RDCORINV_COR7: "",
						RDCORINV_COR10: "",
					},
				],
			},

			rules: {
				// RDCORINV_COR1: [
				// 	{
				// 		validator: CHEVACST001,
				// 		trigger: ["change", "blur"],
				// 	},
				// ],
				// RDCORINV_COR2: [
				// 	{
				// 		validator: dome(0, 10),
				// 		trigger: ["change", "blur"],
				// 	},
				// ],
				// RDCORINV_COR3: [
				// 	{
				// 		validator: dome(0, 10),
				// 		trigger: ["change", "blur"],
				// 	},
				// ],
				// RDCORINV_COR4: [
				// 	{
				// 		validator: dome(0, 10),
				// 		trigger: ["change", "blur"],
				// 	},
				// ],
				// RDCORINV_COR5: [
				// 	{
				// 		validator: dome(0, 10),
				// 		trigger: ["change", "blur"],
				// 	},
				// ],
				// RDCORINV_COR6: [
				// 	{
				// 		validator: dome(0, 10),
				// 		trigger: ["change", "blur"],
				// 	},
				// ],
				// RDCORINV_COR7: [
				// 	{
				// 		validator: dome(0, 10),
				// 		trigger: ["change", "blur"],
				// 	},
				// ],
				// RDCORINV_COR8: [
				// 	{
				// 		validator: dome(0, 10),
				// 		trigger: ["change", "blur"],
				// 	},
				// ],
				// RDCORINV_COR9: [
				// 	{
				// 		validator: dome(0, 10),
				// 		trigger: ["change", "blur"],
				// 	},
				// ],
				// RDCORINV_COR10: [
				// 	{
				// 		validator: dome(0, 10),
				// 		trigger: ["change", "blur"],
				// 	},
				// ],
			},

			loading: false,
		}
	},
	computed: {
		...mapState({
			senstivity_Data: (state) => state.token.senstivity_Data,
			basic_Data: (state) => state.token.basic_Data,
		}),
	},
	mounted() {
		this.setData()
	},
	methods: {
		setData() {
			this.ruleForm.DDNPSGRPNum = this.senstivity_Data.DDVDEPOS_VALUE.length 
			this.addDDNPSGRPNum(this.ruleForm.DDNPSGRPNum)
		},
		queryDetail() {
			// 查询明细
		},
		addDDNPSGRPNum(value) {
			// console.log(value)
			this.ruleForm.DDNPSGRPList = []
			this.ruleForm.DDNPSGRP001 = this.basic_Data.DDNPSGRP001
			for (let index = 0; index < parseInt(value); index++) { 
				let n=index+1
				this.ruleForm.DDNPSGRPList.push({
					index: n.toString(),
					DDNPSGRPtab: [
						{
							RDCORINV_COR1: this.senstivity_Data.DDVDEPOS_VALUE[
								index
							]
								? this.senstivity_Data.DDVDEPOS_VALUE[index][0]
								: "0",
							RDCORINV_COR2: this.senstivity_Data.DDVDEPOS_VALUE[
								index
							]
								? this.senstivity_Data.DDVDEPOS_VALUE[index][1]
								: "0",
							RDCORINV_COR3: this.senstivity_Data.DDVDEPOS_VALUE[
								index
							]
								? this.senstivity_Data.DDVDEPOS_VALUE[index][2]
								: "0",
							RDCORINV_COR4: this.senstivity_Data.DDVDEPOS_VALUE[
								index
							]
								? this.senstivity_Data.DDVDEPOS_VALUE[index][3]
								: "0",
							RDCORINV_COR5: this.senstivity_Data.DDVDEPOS_VALUE[
								index
							]
								? this.senstivity_Data.DDVDEPOS_VALUE[index][4]
								: "0",
							RDCORINV_COR6: this.senstivity_Data.DDVDEPOS_VALUE[
								index
							]
								? this.senstivity_Data.DDVDEPOS_VALUE[index][5]
								: "0",
							RDCORINV_COR8: this.senstivity_Data.DDVDEPOS_VALUE[
								index
							]
								? this.senstivity_Data.DDVDEPOS_VALUE[index][6]
								: "0",
							RDCORINV_COR9: this.senstivity_Data.DDVDEPOS_VALUE[
								index
							]
								? this.senstivity_Data.DDVDEPOS_VALUE[index][7]
								: "0",
							RDCORINV_COR7: this.senstivity_Data.DDVDEPOS_VALUE[
								index
							]
								? this.senstivity_Data.DDVDEPOS_VALUE[index][8]
								: "0",
							RDCORINV_COR10: this.senstivity_Data.DDVDEPOS_VALUE[
								index
							]
								? this.senstivity_Data.DDVDEPOS_VALUE[index][9]
								: "0",
						},
					],
				})
			}
			let tempdata = JSON.parse(JSON.stringify(this.senstivity_Data))
			tempdata.DDNPSGRPNum = this.ruleForm.DDNPSGRPNum
			this.$store.dispatch("upData_senstivity_Data", tempdata)
		},
		submitFun() {
			// console.log(this.ruleForm.DDNPSGRPList)
			this.$refs.form.validate((valid) => {
				if (valid) {
					let tempdata = JSON.parse(
						JSON.stringify(this.senstivity_Data)
					) 
					let tempDDVDEPOS_VALUE = this.ruleForm.DDNPSGRPList.map(
						(item) => {
							let tempDDVDEPOS = []
							for (const key in item.DDNPSGRPtab[0]) {
								if (item.DDNPSGRPtab[0].hasOwnProperty(key)) {
									const element = item.DDNPSGRPtab[0][key]
									tempDDVDEPOS.push(parseFloat(element))
								}
							}
							tempDDVDEPOS.splice(this.basic_Data.DDNPSGRP001)
							return tempDDVDEPOS
						}
					)
					tempdata.DDVDEPOS_VALUE = tempDDVDEPOS_VALUE
					// tempdata.SETPAGEINDEX = this.activeTab
					this.$store.dispatch("upData_senstivity_Data", tempdata) 
					let params = {
						batchid: this.$route.query.id,
						batchinfo: "MINGAN",
						submitjson: JSON.stringify(tempdata),
					}
					// console.log(params)
					this.$appApi
						.BATCH_SUBMIT(params)
						.then((res) => {
							// console.log(res)
							var str = res.data.substring(0, 1)
							var message = res.data.substring(6)
							if (str == "E") {
								this.$notify.error({
									title: "提交失败！",
									message: message,
									type: "success",
								})
							} else if (str == "S") {
								this.$notify({
									message: "提交成功！",
									type: "success",
								})
							}
						})
						.catch((err) => {
							console.log(err)
						})
					this.$emit("changeActiveTab", this.activeTab)
					this.$store.dispatch(
						"change_senstivity_showTab",
						this.activeTab
					)
				}
			})
		},
		tijiao() { 
			this.$refs.form.validate((valid) => {
				if (valid) {
					let tempdata = JSON.parse(
						JSON.stringify(this.senstivity_Data)
					) 
					let tempDDVDEPOS_VALUE = this.ruleForm.DDNPSGRPList.map(
						(item) => {
							let tempDDVDEPOS = []
							for (const key in item.DDNPSGRPtab[0]) {
								if (item.DDNPSGRPtab[0].hasOwnProperty(key)) {
									const element = item.DDNPSGRPtab[0][key]
									tempDDVDEPOS.push(parseFloat(element))
								}
							}
							tempDDVDEPOS.splice(this.basic_Data.DDNPSGRP001)
							return tempDDVDEPOS
						}
					)
					tempdata.DDVDEPOS_VALUE = tempDDVDEPOS_VALUE
					tempdata.SETPAGEINDEX = this.activeTab
					let params = {
						batchid: this.$route.query.id,
						batchinfo: "MINGAN",
						submitjson: JSON.stringify(tempdata),
					} 
					this.$appApi
						.BATCH_SUBMIT(params)
						.then((res) => { 
							var str = res.data.substring(0, 1)
							if (str == "E") {
								let message = res.data.substring(6)
								this.$notify.error({
									title: "提交失败！",
									message: message,
									type: "success",
								})
							} else if (str == "S") {
								this.$notify({
									message: "提交成功！",
									type: "success",
								})
								this.$router.go(-1)
							}
						})
						.catch((err) => {
							console.log(err)
						})
				}
			})
		},
		daochu() {
			//导出
		},
	},
}
</script>
<style lang="scss" scoped>
.page-flex-row /deep/ .el-collapse-item__header {
	background: #f3f9fe;
}
</style>